package service

import (
	"context"
	"go-mall/dao"
	"go-mall/pkg/e"
	"go-mall/serializer"
)

type CategoriesService struct {
}

func (service *CategoriesService) List(ctx context.Context) serializer.Response {
	code := e.Success
	categoriesDao := dao.NewCategoriesDao(ctx)
	categories, err := categoriesDao.ListCategories()
	if err != nil {
		code = e.Error
		return serializer.Response{
			Status: code,
			Msg:    e.GetMsg(code),
			Data:   categories,
		}
	}
	return serializer.BuildListResponse(serializer.BuildListCategories(categories), uint(len(categories)))
}
